package com.dswz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dswz.dao.AdminDao;
import com.dswz.po.Admin;
import com.dswz.po.AdminQuery;
import com.dswz.service.AdminService;

@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminDao adminDao;

	@Transactional(readOnly = true)
	public Admin getAdmin(String username, Byte isDel) throws Exception {
		AdminQuery adminQuery = new AdminQuery();
		AdminQuery.Criteria createCriteria = adminQuery.createCriteria();
		if (isDel != null) {
			createCriteria.andAdminIsDelEqualTo(isDel);
		}
		List<Admin> adminList = this.adminDao.selectByExample(adminQuery);
		if ((adminList != null) && (adminList.size() > 0)) {
			return (Admin) adminList.get(0);
		}
		return null;
	}

	public void updateAdmin(Admin admin) throws Exception {
		this.adminDao.updateByPrimaryKeySelective(admin);
	}
}
